import {
	request
} from '@/util/request.js'
import {
	handleErrorCode
} from '@/util/common/message.js'
	// 返回data
export async function onGotApiData(apiUrl, method, params, callback) {
	params.platform_no = 1
	await request({
		url: apiUrl,
		method: method,
		data: params,
		withCredentials: true,
	}).then(res => {
		console.log("api请求成功",res)
		if (res.code && res.code == 200) {
			console.log("我是200")
			callback && callback(res.data);
		} else if(res.code && res.code == 401){
			console.log("我是401")
			// uni.showToast({
			// 	title: '权限不足 请开通套餐',
			// 	//将值设置为 success 或者直接不用写icon这个参数
			// 	icon: 'none',
			// 	//显示持续时间为 2秒
			// 	duration: 1000
			// })   
			callback && callback(res);
		}else if(res.code && res.code == 402){
			console.log("结果返回402",res)
			// uni.navigateTo({
			// 	url: '/pages/payvip/payvip?shop_id=' + res.data.shop_id + '&shop_type=' + res.data.shop_type,
			// });
			// return
			callback && callback(res);
		}else{
			callback && callback(res);
		}
		
	}).catch(function(error) {
		console.log('捕捉到了错误',error)
		// that.onMessageShow(error, 'error', 1500);
	});
}
// 返回全部
export async function onGotApi(apiUrl, method, params, callback) {
	params.platform_no = 1
	await request({
		url: apiUrl,
		method: method,
		data: params,
		withCredentials: true,
	}).then(res => {
		console.log("api请求成功",res)	
		callback && callback(res);
	}).catch(function(error) {
		console.log('捕捉到了错误',error)
		// that.onMessageShow(error, 'error', 1500);
	});
}
//统计事件
export async function addClick(key, key2 = "") {
	// let channel_no = uni.getStorageSync('xcx')
	return new Promise((resolve, reject) => {
		uni.request({
			url: 'https://data-api.ksbmtb.com:8882/api/app/event/add', //仅为示例，并非真实接口地址。
			method: "POST",
			data: {
				event_name: key,
				project_name: 'shop-subletting',
				event_value: key2,
				// channel_no: "VXHead_CS"
				channel_no:'xcx'
			},
			header: {
				'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
			},
			success: async (res) => {
				resolve(res.result)
			}
		});
	});
}

export async function radioDF() {
	let res = await request({
		url: 'api/radio/radio',
		method: 'POST',
	})
	handleErrorCode(res.code, res.massage)
	return res
}
export async function createMerchant(data) {
	let res = await request({
		url: 'v4/merchant/createMerchant',
		method: 'POST',
		data
	})
	handleErrorCode(res.code, res.massage)
	return res
}
export async function getWxV2(data) {
	let res = await request({
		url: 'api/merchant_one_v2/getWxV2',
		method: 'POST',
		data
	})
	handleErrorCode(res.code, res.massage)
	return res
}
export async function feedback(data) {
	let res = await request({
		url: 'api/other/feedback',
		method: 'POST',
		data
	})
	handleErrorCode(res.code, res.massage)
	return res
}
export async function orderP(data) {
	let res = await request({
		url: 'v4/merchant/order',
		method: 'POST',
		data
	})
	handleErrorCode(res.code, res.massage)
	return res
}
export async function getMerchantByPhone(data) {
	let res = await request({
		url: 'v4/merchant/getMerchantByPhone',
		method: 'get',
		data
	})
	handleErrorCode(res.code, res.massage)
	return res
}
export async function updateSubMerchant(data) {
	let res = await request({
		url: 'v4/merchant/updateSubMerchant',
		method: 'POST',
		data
	})
	handleErrorCode(res.code, res.massage)
	return res
}
export async function getOpenIdDy(data) {
	let res = await request({
		url: '/util/getOpenIdDy',
		method: 'get',
		data
	})
	handleErrorCode(res.code, res.massage)
	return res
}
